import { getAllRoleList, isAccountExist } from '@/api/demo/system';
import { BasicColumn, FormSchema } from '@/components/Table';
import dayjs from 'dayjs';

/**
 * transform mock data
 * {
 *  0: '华东分部',
 * '0-0': '华东分部-研发部'
 * '0-1': '华东分部-市场部',
 *  ...
 * }
 */
export const deptMap = (() => {
  const pDept = ['华东分部', '华南分部', '西北分部'];
  const cDept = ['研发部', '市场部', '商务部', '财务部'];

  return pDept.reduce((map, p, pIdx) => {
    map[pIdx] = p;

    cDept.forEach((c, cIndex) => (map[`${pIdx}-${cIndex}`] = `${p}-${c}`));

    return map;
  }, {});
})();

export const columns: BasicColumn[] = [
  {
    title: '反馈类型',
    dataIndex: 'dept',
    width: 120,
    customRender: ({ value }) => {
      return deptMap[value];
    },
  },
  {
    title: '联系人',
    dataIndex: 'account',
    width: 120,
  },
  {
    title: '电话',
    dataIndex: 'mobile',
    width: 120,
  },
  {
    title: '邮箱',
    dataIndex: 'email',
    width: 120,
    align: 'left',
  },
  {
    title: '所在地',
    dataIndex: 'email',
    width: 120,
    align: 'left',
  },
  {
    title: 'IP地址',
    dataIndex: 'ip',
    width: 120,
  },
  {
    title: '反馈时间',
    dataIndex: 'id',
    width: 180,
    sorter: true,
    fixed: 'right',
    customRender: ({record})=>{
      return record.createTime;
    }
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: '[startDate, endDate]',
    label: '反馈时间',
    labelWidth: 80,
    component: 'RangePicker',
    colProps: { xs: 24, xl: 12, lg: 8, xxl: 6 },
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      placeholder: ['开始时间', '结束时间'],
      showTime: { format: 'HH:mm:ss' },
    },
    defaultValue: [
      dayjs(
        new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - 7),
      ).format('YYYY-MM-DD'),
      dayjs(new Date()).format('YYYY-MM-DD'),
    ],
  },
  {
    labelWidth: 80,
    field: 'account',
    label: '联系人',
    component: 'Input',
    colProps: { xs: 24, xl: 12, lg: 8, xxl: 6 },
  },
  {
    labelWidth: 80,
    field: 'email',
    label: '邮箱',
    component: 'Input',
    colProps: { xs: 24, xl: 12, lg: 8, xxl: 6 },
  },
];
